package com.wondream.myframework.app.unipay.up;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class STP10003 {

    private final Logger logger = LogManager.getLogger(STP10003.class);

    @Test
    void execute(){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss0SSS");
        String orderNo = formatter.format(new Date());

        String payOrderNo = formatter.format(new Date());
        String MERC_ID = "201812100000002007";
        String MERC_ORD_NO = orderNo;
        String orgPayOrderNo = orderNo;
        String txAmtStr_penny = "1"; // 以分为单位
        String PAY_NOTIFY_URL = "";
        String posOrderNo = "1000";
        String SHOP_ID = "201812200000001350";
        String TRM_NO = "";
        String GOODS_NM = "";
        String GOODS_DESC = "";
        String payToken = "52016182973555995807132";
//        String payToken = "52016183033808097482965";
        //银联单品信息
        String detail = "";
        String payChannel = "UP";
        logger.info("payChannel={}"+payChannel);
        String PAY_TYP = "02";
        String regex = "^[0-9]*[1-9][0-9]*$";
        // 合法性检查
        if (!txAmtStr_penny.matches(regex)) {
            logger.info("金额格式错误，商户接口中金额均为正整数，以分为单位");
        }
        if (txAmtStr_penny.length() >= 13) {
            logger.info("金额格式错误，商户接口中金额均为正整数，以分为单位，长度小于13位");
        }
        regex = "^((https|http)?://)+(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+\\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\\.[a-z]{2,6})(:[0-9]{1,4})?((/?)|(/[0-9a-zA-Z_!~*'().;?:@&=+$,%#-]+)+/?)$";

        if (!StringUtils.isBlank(PAY_NOTIFY_URL) && !PAY_NOTIFY_URL.matches(regex)) {
            logger.info("通知地址非法，请输入正确的http或者https的url");
        }

        if (StringUtils.isBlank(payChannel)) {
            logger.info("支付渠道数据非法");
        }
        if (payToken.length() >= 30) {
            logger.info("付款码非法，长度太长");
        }
        // 设置默认值
        if (StringUtils.isBlank(GOODS_DESC)) {
            GOODS_DESC = "超市购物";
        }
        if (StringUtils.isBlank(GOODS_NM)) {
            GOODS_NM = "超市购物";
        }

        Map<String, Object> sqldatamap = new HashMap<String, Object>();
        // 查询商户
        Map<String, Object> mercInfoMap = new HashMap<>();
        if (mercInfoMap == null) {
            logger.info("找不到该商户基本信息");
        }
    }

}
